package org.macpro.alone.server.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class TimeTool {
	/**
	 * ���12λ�����ڱ���
	 */
	public static String getTimeDate12() {
		// yyyyMMddhhmm
		SimpleDateFormat _sdf = new SimpleDateFormat("yyyyMMddhhmm");
		Date _date = new Date();

		return _sdf.format(_date);
	}

	/**
	 * ���8λ�����ڱ���
	 */
	public static String getTimeDate8() {
		// yyyyMMdd
		SimpleDateFormat _sdf = new SimpleDateFormat("yyyyMMdd");
		Date _date = new Date();

		return _sdf.format(_date);
	}
	/**
	 * ���14λ�����ڱ���
	 */
	public static String getTimeDate14() {
		/* yyyyMMddhhmmss */
		SimpleDateFormat _sdf = new SimpleDateFormat("yyyyMMddhhmmss");
		Date _date = new Date();

		return _sdf.format(_date);
	}
	/**
	 * ���18λ���漴��
	 */
	public static String getRandom18() {
		// TODO Auto-generated method stub
		String _random = UUID.randomUUID().toString();

		return _random.substring(0, 18);
	}

	@SuppressWarnings("static-access")
	/**
	 * ���32λ���ڼ��漴β������
	 */
	public static String getOid() {
		// TODO Auto-generated method stub
		String _oid = new TimeTool().getTimeDate14()
				+ new TimeTool().getRandom18();
		return _oid;
	}

	public static String dateToMillis(Date date) {
		return zeroPadString(Long.toString(date.getTime()), 15);
	}

	public static String zeroPadString(String string, int length) {
		if (string == null || string.length() > length) {
			return string;
		}
		StringBuilder buf = new StringBuilder(length);
		buf.append(zeroArray, 0, length - string.length()).append(string);
		return buf.toString();
	}

	private static final char[] zeroArray = "0000000000000000000000000000000000000000000000000000000000000000"
			.toCharArray();

}
